<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
    <title>支付</title>
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/qrcode.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css">
</head>

<body>
    <div class="container">
        <div class="row">
            <p class="text-center"><h2>扫码支付</h2></p>
        </div>
        <div class="col-md-8">
            <form name="reqForm">
                <div class="form-group">
                    <label for="partnerId">平台ID</label>
                    <input type="text" class="form-control" value="test" name="partnerId" id="partnerId" placeholder="平台ID">
                </div>
                <div class="form-group">
                    <label for="merchantId">商户ID</label>
                    <input type="text" class="form-control" value="12345678901234567890" name="merchantId" id="merchantId" placeholder="商户ID">
                </div>
                <div class="form-group">
                    <label for="orderNo">订单号</label>
                    <input type="text" class="form-control" value="oderno123412341234" name="orderNo" id="orderNo" placeholder="订单号">
                </div>
                <div class="form-group">
                    <label for="memo">备注</label>
                    <input type="text" class="form-control" value="tradememo" name="memo" id="memo" placeholder="备注">
                </div>
                <div class="form-group">
                    <label for="amount">金额</label>
                    <input type="text" class="form-control" value="14304" name="amount" id="amount" placeholder="金额">
                </div>
                <div class="radio-inline">
                    <label>
                        <input type="radio" name="payMethod" id="optionsRadios1" value="ALIPAY" checked>
                        支付宝
                    </label>
                </div>
                <div class="radio-inline">
                    <label>
                        <input type="radio" name="payMethod" id="optionsRadios2" value="WECHAT">
                        微信
                    </label>
                </div>
                <button type="button" id="btn" class="btn btn-primary">生成二维码</button>

            </form>
            <div class="form-group">
                <input type="text" class="form-control" id="furl">
                <button type="button" id="forward" class="btn btn-default">跳转</button>
            </div>
        </div>
        <div class="col-md-4">
            <div id="qrcode"></div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var qrcode;
    $(function() {
        qrcode = new QRCode(document.getElementById("qrcode"), "http://baidu.com");
    });
    var reqHost = "http://"+window.location.host+"/gateway.html?";

    $("#forward").click(function () {
        window.location.href= $("#furl").val();
    });
    $("#btn").click(function () {
        var elements = document.forms["reqForm"].elements;
        var paramUrl="";
        for (var i=0; i<elements.length; i++){
            var ele = elements[i];
            if(!("radio" === ele.type&&!ele.checked)&&"button" !== ele.type){
                paramUrl += (ele.name+"="+ele.value+"&");
            }
        }
        paramUrl = reqHost+"service=pay&"+paramUrl;
        $.ajax({
            type: "POST",
            url: "/pay/key",
            data:{
                paramUrl:paramUrl
            }
        }).done(function ( data ) {
            $("#furl").val(paramUrl+"sign="+data);
            qrcode.clear();
            qrcode.makeCode($("#furl").val());
        });

    });
</script>

</html>